package com.course.db;

import java.sql.ResultSet;

public class CourseBasic extends ExecuteDB {

	//members
	private int Id;
	private String classno;
	private String name;
	private String type;
	private int credit;
	private String teach_style;
	private String test_style;
	private int course_span;
	private int students_low;
	private int students_high;
	private String teach_equipments;
	private String introduction;
	private String openterm;
	private String year;
	private String grade;
	private String teach_location;
	private String teach_time;
	private String teachers;
	private int check_status; //0 states checking, 1 states checked, >1 states checked not passed
	private int num_of_students;
	private String checkcomment;
	private String strSql;
	
	public CourseBasic()
	{
		this.Id = 0;
		this.classno = "";
		this.name = "";
		this.type = "";
		this.credit = 0;
		this.teach_style = "";
		this.test_style = "";
		this.course_span = 0;
		this.students_low = 0;
		this.students_high = 0;
		this.teach_equipments = "";
		this.introduction = "";
		this.openterm = "";
		this.year = "";
		this.grade = "";
		this.teach_location = "";
		this.teach_time = "";
		this.teachers = "";
		this.check_status = 0;
		this.num_of_students = 0;
		this.checkcomment = "";
	}
	
	public String CountSql()
	{
		this.strSql = "select count(*) from course_basic";
		return this.strSql;
	} 
	
	//add a CousrBasic
	public boolean add()
	{

		this.strSql="insert into course_basic ";
		this.strSql=this.strSql + "(classno,name,type,credit,teach_style,test_style,course_span,students_low,students_high,teach_equipments,introduction,openterm,year,grade,teach_location,teach_time,teachers,checkstatus,num_of_students,checkcomment) ";
		this.strSql=this.strSql + "values('" + this.classno + "','" + this.name + "','" + this.type+ "'," + this.credit+ ",'" + this.teach_style+ "','" + this.test_style+ "'," + this.course_span+ "," + this.students_low+ "," + this.students_high+ ",'" + this.teach_equipments+ "','" + this.introduction+ "','" + this.openterm+ "','" + this.year+ "','" + this.grade+ "','" + this.teach_location+ "','" + this.teach_time+ "','" + this.teachers+ "','" + this.check_status+ "','" + this.num_of_students+ "','" + this.checkcomment+ "')";
		System.out.println(this.strSql);
		boolean isAdd = super.exeSql(this.strSql);
        return isAdd;
	}
	
	public int lastid()
	{
		int lid = 0;
		this.strSql = "select last_insert_id() as id from course_basic limit 1";
		ResultSet rs = null;
		try
		{
			rs = super.exeQuery(this.strSql);
			if (rs.next())
				lid = rs.getInt("id");
		}
		catch(Exception e)
		{
			System.out.println(e.toString());
		}
		return lid;
	}
	
	//delete a CourseBasic by id
    public boolean delete(int CourseBasicID)
    {
       this.strSql = "delete from course_basic where Id in (";
       this.strSql = this.strSql + CourseBasicID +")";

       boolean isDelete = super.exeSql(this.strSql);
       return isDelete;
    }
    
  //initialize CourseBasic information
 	public boolean init()
	{
		this.strSql="select * from `course_basic` where Id=";
		this.strSql=this.strSql + "'" + this.Id + "'";
		try
		{
			ResultSet rs = super.exeQuery(this.strSql);
			if (rs.next())
			{
				this.Id=rs.getInt("Id");
				this.classno=rs.getString("classno");
				this.name=rs.getString("name");
				this.type=rs.getString("type");
				this.credit=rs.getInt("credit");
				this.teach_style=rs.getString("teach_style");
				this.test_style=rs.getString("test_style");
				this.course_span=rs.getInt("course_span");
				this.students_low=rs.getInt("students_low");
				this.students_high=rs.getInt("students_high");
				this.teach_equipments=rs.getString("teach_equipments");
				this.introduction=rs.getString("introduction");
				this.openterm=rs.getString("openterm");
				this.year=rs.getString("year");
				this.grade=rs.getString("grade");
				this.teach_location=rs.getString("teach_location");
				this.teach_time=rs.getString("teach_time");
				this.teachers=rs.getString("teachers");
				this.check_status = rs.getInt("checkstatus");
				this.num_of_students = rs.getInt("num_of_students");
				this.checkcomment = rs.getString("checkcomment");
				
				return true;
			}
			else
			{
				return false;
			}
		}
		catch(Exception e)
		{
			System.out.println(e.toString());
			return false;
		}
	}
 	
 	//modify CourseBasic infomation
    public boolean modify_coursebasic()
	{
		this.strSql="update course_basic set";
		this.strSql=this.strSql + " classno=" + "'" + this.classno + "',";
		this.strSql=this.strSql + " name=" + "'" + this.name + "',";
		this.strSql=this.strSql + " type=" + this.type + ",";
		this.strSql=this.strSql + " credit=" + this.credit + ",";
		this.strSql=this.strSql + " teach_style=" + this.teach_style + ",";
		this.strSql=this.strSql + " test_style=" + this.test_style + ",";
		this.strSql=this.strSql + " course_span=" + this.course_span + ",";
		this.strSql=this.strSql + " students_low=" + this.students_low + ",";
		this.strSql=this.strSql + " students_high=" + this.students_high + ",";
		this.strSql=this.strSql + " teach_equipments=" + this.teach_equipments + ",";
		this.strSql=this.strSql + " introduction=" + this.introduction + ",";
		this.strSql=this.strSql + " openterm=" + this.openterm + ",";
		this.strSql=this.strSql + " year=" + this.year + ",";
		this.strSql=this.strSql + " grade=" + this.grade + ",";
		this.strSql=this.strSql + " teach_location=" + this.teach_location + ",";
		this.strSql=this.strSql + " teach_time=" + this.teach_time + ",";
		this.strSql=this.strSql + " teachers=" + this.teachers + ",";
		this.strSql=this.strSql + " checkstatus=" + this.check_status + ",";
		this.strSql=this.strSql + " num_of_students=" + this.num_of_students + ",";
		this.strSql=this.strSql + " checkcomment=" + this.checkcomment ;
		this.strSql=this.strSql + " where Id=" + this.Id;
		
		boolean isUpdate = super.exeSql(this.strSql);

		return isUpdate;
	}
 	
 	//show CourseBasic
    public ResultSet show_coursebasic()
	{
		this.strSql="select * from `course_basic`";
		ResultSet rs = null;
		try
		{
			rs = super.exeQuery(this.strSql);
		}
		catch(Exception e)
		{
			System.out.println(e.toString());
		}
		return rs;
	}
    
	//show wait_check
    public ResultSet wait_check()
	{
		this.strSql="select * from `course_basic` where checkstatus = 0";
		ResultSet rs = null;
		try
		{
			rs = super.exeQuery(this.strSql);
		}
		catch(Exception e)
		{
			System.out.println(e.toString());
		}
		return rs;
	}
    
  //show wait_check
    public ResultSet show_checked()
	{
		this.strSql="select * from `course_basic` where checkstatus > 0";
		ResultSet rs = null;
		try
		{
			rs = super.exeQuery(this.strSql);
		}
		catch(Exception e)
		{
			System.out.println(e.toString());
		}
		return rs;
	}

	public int getId() {
		return Id;
	}

	public void setId(int id) {
		Id = id;
	}

	public String getClassno() {
		return classno;
	}

	public void setClassno(String classno) {
		this.classno = classno;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public int getCredit() {
		return credit;
	}

	public void setCredit(int credit) {
		this.credit = credit;
	}

	public String getTeach_style() {
		return teach_style;
	}

	public void setTeach_style(String teach_style) {
		this.teach_style = teach_style;
	}

	public String getTest_style() {
		return test_style;
	}

	public void setTest_style(String test_style) {
		this.test_style = test_style;
	}

	public int getCourse_span() {
		return course_span;
	}

	public void setCourse_span(int course_span) {
		this.course_span = course_span;
	}

	public int getStudents_low() {
		return students_low;
	}

	public void setStudents_low(int students_low) {
		this.students_low = students_low;
	}

	public int getStudents_high() {
		return students_high;
	}

	public void setStudents_high(int students_high) {
		this.students_high = students_high;
	}

	public String getTeach_equipments() {
		return teach_equipments;
	}

	public void setTeach_equipments(String teach_equipments) {
		this.teach_equipments = teach_equipments;
	}

	public String getIntroduction() {
		return introduction;
	}

	public void setIntroduction(String introduction) {
		this.introduction = introduction;
	}

	public String getStrSql() {
		return strSql;
	}

	public void setStrSql(String strSql) {
		this.strSql = strSql;
	}

	public String getOpenterm() {
		return openterm;
	}

	public void setOpenterm(String openterm) {
		this.openterm = openterm;
	}

	public String getYear() {
		return year;
	}

	public void setYear(String year) {
		this.year = year;
	}

	public String getGrade() {
		return grade;
	}

	public void setGrade(String grade) {
		this.grade = grade;
	}

	public String getTeach_location() {
		return teach_location;
	}

	public void setTeach_location(String teach_location) {
		this.teach_location = teach_location;
	}

	public String getTeach_time() {
		return teach_time;
	}

	public void setTeach_time(String teach_time) {
		this.teach_time = teach_time;
	}

	public String getTeachers() {
		return teachers;
	}

	public void setTeachers(String teachers) {
		this.teachers = teachers;
	}

	public int getCheck_status() {
		return check_status;
	}

	public void setCheck_status(int check_status) {
		this.check_status = check_status;
	}

	public int getNum_of_students() {
		return num_of_students;
	}

	public void setNum_of_students(int num_of_students) {
		this.num_of_students = num_of_students;
	}
    
    
}
